package com.boot.core.common.base;/**
 * @description
 * @autor xbwu on 2017/8/17.
 */


import com.boot.core.common.enums.ResultEnum;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * ajax返回结果封装
 * @author xbwu
 * @create 2017-08-17 
 **/
@Data
public class ResultWapper {

    private String msg;

    private Map<String,Object> result=new HashMap<>();

    private ResultEnum resultType;

    public static ResultWapper getInstance(){
        return new ResultWapper();
    }

    public static ResultWapper success(String msg){
        ResultWapper rw=new ResultWapper();
        rw.setMsg(msg);
        rw.setResultType(ResultEnum.SUCCESS);
        return rw;
    }
    public static ResultWapper success(){
        return success("");
    }

    public static ResultWapper error(String msg){
        return error(msg,ResultEnum.ERROR);
    }
    public static ResultWapper error(String msg,ResultEnum re){
        ResultWapper rw=getInstance();
        rw.setMsg(msg);
        rw.setResultType(re);
        return rw;
    }
    public static ResultWapper warn(String msg, Map<String,Object> result){
        ResultWapper rw=getInstance();
        rw.setMsg(msg);
        rw.setResult(result);
        rw.setResultType(ResultEnum.WARN);
        return rw;
    }

    public ResultWapper addResult(String key, Object value){
        result.put(key,value);
        return this;
    }
}
